package physics.movement;

import model.objects.GameObject;
import model.objects.Level;
import physics.EuclideanVector;


/**
 * Describes the movement behavior for an object that moves at a constant speed
 * regardless of global forces until it reaches the edge of the level, at which
 * point it wraps around and begins its path again.
 * 
 * @author geo4
 * 
 */
public class WrappingMovingPlatformStrategy implements MovementStrategy {

    private double myXVelocity;
    private double myYVelocity;

    /**
     * Creates a new instance of a WrappingMovingPlatformStrategy which moves in
     * the direction and speed of the x and y velocities specified.
     * 
     * @param xVelocity x component of the platform's velocity
     * @param yVelocity y component of the platform's velocity
     */
    public WrappingMovingPlatformStrategy (double xVelocity, double yVelocity) {
        myXVelocity = xVelocity;
        myYVelocity = yVelocity;
    }

    @Override
    public void updatePosition (Level level, GameObject mover, double dt, EuclideanVector... globalForces) {

        mover.setPosition(mover.getBounds().getX() + mover.getVelocity().getX(), mover.getBounds()
                .getY() + mover.getVelocity().getY());

        if (mover.getBounds().getX() > level.getWidth()) {
            mover.setPosition(mover.getBounds().getX() - level.getWidth(), mover.getBounds().getY());
        }
        else if (mover.getBounds().getX() < 0) {
            mover.setPosition(mover.getBounds().getX() + level.getWidth(), mover.getBounds().getY());
        }
        if (mover.getBounds().getY() > level.getHeight()) {
            mover.setPosition(mover.getBounds().getX(),
                              mover.getBounds().getY() - level.getHeight());
        }
        else if (mover.getBounds().getY() < 0) {
            mover.setPosition(mover.getBounds().getX(),
                              mover.getBounds().getY() + level.getHeight());
        }
    }

}
